#include"Library.h"

void login()
{
	char username[20];
	char password[20];
	FILE* fi = fopen("用户信息.txt", "r+b");
	if (fi == NULL)
	{
		fi = fopen("用户信息.txt", "w+b");
	}
	printf("*************************欢迎使用高校图书管理系统**********************\n");
	printf("请输入用户名:\n");
	scanf("%s", &username);
	printf("请输入密码:\n");
	scanf("%s", &password);
	char fname[20];
	char fpass[20];
	while (!feof(fi))
	{
		fread(fname, 20, 1, fi);
		fread(fpass, 20, 1, fi);
		if (strcmp(fname, username) == 0)
		{
			if (strcmp(fpass, password) == 0)
			{
				printf("登录成功!\n");
				printf("按任意键继续执行\n");
				getch();
				fclose(fi);
				return;
			}
			else
			{
				printf("密码错误!\n");
				printf("按任意键程序退出\n");
				getch();
				exit(0);
			}
		}
	}
	fwrite(username, 20, 1, fi);
	fwrite(password, 20, 1, fi);
	printf("注册成功!\n");
	printf("按任意键继续执行\n");
	getch();
	fclose(fi);
}

